import QtQuick 2.0
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import Quick.DataComponent.API 0.1
import Quick.DataComponent.JsonOp 0.1
import "Weather/js/getValue.js"  as Parse


Page{
    id:root
    title: "Weather"

    property string json:GetResult.weather.result

    property var rootObj

    property var weatherRoot

    property var realTime

    property var realWeather


    Flow{
        anchors.fill: parent
        anchors.margins: 4
        spacing: 10
        flow:Flow.TopToBottom
        Label {
            id:city
        }
        Label {
            id:time
        }
        Label {
            id:weather
        }
    }

    function updateData(){
        rootObj = JsonOp.strToObj(json)
        weatherRoot = JsonOp.getValueFromObj(rootObj,"result")
        realTime = JsonOp.getValueFromObj(weatherRoot,"realtime")
        realWeather = JsonOp.getValueFromObj(realTime,"weather")
    }
    function updateDisplay(){
        city.text = realTime["city_name"]
        time.text  = realTime["moon"]+realTime["time"]
        weather.text = realWeather["info"]+realWeather["temperature"]
    }

    onJsonChanged: {
        if(0 !== json.length){
            updateData()
            updateDisplay()
        }
    }


    Button{
        onClicked: {
            console.log(GetResult.weather.result)
            json = GetResult.weather.result
        }
    }


    function getData(){


    }


}
